#ifndef DATABASE_H
#define DATABASE_H

#include <mysql/mysql.h>
#include "user.h"

// 数据库连接配置
#define DB_HOST "localhost"
#define DB_USER "root"
#define DB_PASSWORD ""
#define DB_NAME "Photovoltaic_Monitoring_System"

// 数据库操作函数声明
MYSQL *dbConnect();
void dbDisconnect(MYSQL *conn);
int dbInsertUser(MYSQL *conn, const UserInfo *user);
int dbGetUser(MYSQL *conn, const char *username, UserInfo *user);
int dbCheckUserExists(MYSQL *conn, const char *username);
int dbInsertLog(MYSQL *conn, int id, const char *time, const char *logerror, const char *info);

// 生产数据操作函数
int dbInsertProductionData(MYSQL *conn, const char *waferid, const char *equipmentid, 
                          const char *defecttyme, const char *productionline, 
                          const char *reworkflag, const char *idaddress);

// 生产统计数据操作函数
int dbInsertProductionSummary(MYSQL *conn, const char *shift, const char *time, 
                             const char *lineno, int output, 
                             double qualifiedrata, double Agraderata, double reworkrata);

// 按小时统计生产数据函数
int dbSummarizeHourlyData(MYSQL *conn, const char *timeRange);

#endif // DATABASE_H